/**
 * 投诉模块，提供投诉管理相关业务功能
 * 
 * @Date: 2018-1-11
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","msgServ", "ajaxServ", "formServ", "btnServ"],
		function($,datagridServ, msgServ, ajaxServ, formServ, btnServ) {

			'use strict';

			var _bizcode = 'dutiesComplain',_buttonConfig,
				//锚记datagrid目标元素
				
				edit_window_id = 'pop-dutiesComplain-win',
				//编辑弹窗对象及弹窗按钮对象
				$edit_window,window_btn,
				
				//业务表单对象
				$form,
				formEl, formData = 0, 
				 
				//门户单独提供的保存方法，绕过权限控制，避免因未登陆系统无法执行保存操作
				saveUrl = '/portal/complainSave'		
				

			var public_method = {
				
				
				init:function(doc){
					private_method.init(doc);
				}
				,
				openPage:function(){
					var _param = {
						window:$('#'+edit_window_id),
						href:'/portal/getComplainPopPage',						
						flag:false,
						//maximized:true,
						width: 850,
						height: 500,
						title:'投诉举报'
					}
						
					datagridServ.windowEdit(_param);
				}
				
			}

			var private_method = {
				init : function(doc) {
					if (window.console) {
					console.info('complain modules gets ready and been loaded.');
					}
					_buttonConfig={						
						 "保存":private_method.submit,
						 "取消":private_method.cancel									
					}
					
					private_method.initElement()
				},
				
				
				
				
				//初始化元素
				initElement:function(){				
					
					// 编辑窗口初始化
					// 编辑窗口初始化
					var _btn = $('#'+edit_window_id + ' .btn-save')
					_btn.bind('click',private_method.submit)
					_btn = $('#'+edit_window_id + ' .btn-cancel')
					_btn.bind('click',private_method.cancel)				

				},				
				
						
				
				// 提交form
				submit : function(evt) {
					$form = $('#'+edit_window_id + ' .main-form');
					
					var _data = formServ.getDataObj({form:$form,container:edit_window_id})
					
					var $data = $.toJSON(_data);
					var ajaxParam = {
						contentType : 'appliction/json;charset=utf-8',
						url: saveUrl,
						data : $data,
						type :'post',
						success:function(data){
							$form.form('load',data)							
							msgServ.Msgslide('保存操作成功');							
						},
						error:function(){							
							msgServ.Msgslide('保存操作失败。。。');							
						}
					}					
					$.ajax(ajaxParam)					
				},				
				
				//
				cancel : function() {
					$('#'+edit_window_id).window('close');
				}
			};
			
			return public_method;

		});